//
//  UserService.m
//  BTCoin
//
//  Created by Robin on 12/03/2018.
//  Copyright © 2018 Robin. All rights reserved.
//

#import "UserService.h"
#import "UserInfo.h"

@implementation UserService

DEFINE_SINGLETON_FOR_CLASS(UserService)

#pragma mark - 登录
- (void)loginApp:(NSDictionary *)parDict success:(successResponseBlock)successBlock fail:(failResponseBlock)failBlock {
    NSString * urlStr = [NSString stringWithFormat:@"%@/user/login/index.do",BaseHttpUrl];
    
    [BaseService post:urlStr dictionay:parDict timeout:SERVICETIMEOUT success:^(id responseObject) {
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil removingNulls:YES ignoreArrays:NO];
        successBlock(dict);
    } fail:^(NSError *error) {
        failBlock(error);
    }];
}

#pragma mark - 获取短信验证码
- (void)getValidateCode:(NSDictionary *)parDict success:(successResponseBlock)successBlock fail:(failResponseBlock)failBlock {
    NSString * urlStr = [NSString stringWithFormat:@"%@/user/sendMsg.do",BaseHttpUrl];
    
    [BaseService post:urlStr dictionay:parDict timeout:SERVICETIMEOUT success:^(id responseObject) {
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil removingNulls:YES ignoreArrays:NO];
        successBlock(dict);
    } fail:^(NSError *error) {
        failBlock(error);
    }];
}

#pragma mark - 注册
- (void)registerAccount:(NSDictionary *)parDict success:(successResponseBlock)successBlock fail:(failResponseBlock)failBlock {
    NSString * urlStr = [NSString stringWithFormat:@"%@/user/reg/index.do",BaseHttpUrl];
    
    [BaseService post:urlStr dictionay:parDict timeout:SERVICETIMEOUT success:^(id responseObject) {
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil removingNulls:YES ignoreArrays:NO];
        successBlock(dict);
    } fail:^(NSError *error) {
        failBlock(error);
    }];
}

#pragma mark - 发邮箱验证码
- (void)getEmailValidateCode:(NSString *)email success:(successResponseBlock)successBlock fail:(failResponseBlock)failBlock {
    NSString * urlStr = [NSString stringWithFormat:@"%@/user/sendMailCode.do",BaseHttpUrl];
    
    [BaseService post:urlStr dictionay:@{@"email":email} timeout:SERVICETIMEOUT success:^(id responseObject) {
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil removingNulls:YES ignoreArrays:NO];
        successBlock(dict);
    } fail:^(NSError *error) {
        failBlock(error);
    }];
}

#pragma mark - 基本信息
- (void)getSecurity:(successResponseBlock)successBlock fail:(failResponseBlock)failBlock {
    
    NSString * urlStr = [NSString stringWithFormat:@"%@/user/security.do",BaseHttpUrl];
    
    [BaseService post:urlStr headerDictionay:[[UserInfo sharedUserInfo] getHeaderDic] timeout:SERVICETIMEOUT success:^(id responseObject) {
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil removingNulls:YES ignoreArrays:NO];
        successBlock(dict);
    } fail:^(NSError *error) {
        failBlock(error);
    }];
}

#pragma mark - 绑定实名账户
- (void)validateIdentity:(NSDictionary *)parDict success:(successResponseBlock)successBlock fail:(failResponseBlock)failBlock {
    NSString * para = [parDict toHttpUrlPara];
    NSString * urlStr = [NSString stringWithFormat:@"%@/user/validateIdentity.do?%@",BaseHttpUrl,para];
    
    [BaseService post:urlStr headerDictionay:[[UserInfo sharedUserInfo] getHeaderDic]  timeout:SERVICETIMEOUT success:^(id responseObject) {
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil removingNulls:YES ignoreArrays:NO];
        successBlock(dict);
    } fail:^(NSError *error) {
        failBlock(error);
    }];
}

#pragma mark - 上传身份证图片
- (void)uploadIDImage:(UIImage *)image success:(successResponseBlock)successBlock fail:(void (^)(void))failBlock {
    NSString * urlStr = [NSString stringWithFormat:@"%@/common/upload.do",BaseHttpUrl];
    
    [BaseService postUploadWithUrl:urlStr image:image success:^(id responseObject) {
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil removingNulls:YES ignoreArrays:NO];
        successBlock(dict);
    } fail:^{
        failBlock();
    }];
}

#pragma mark - 身份证照片审核
- (void)validateKyc:(NSDictionary *)parDict success:(successResponseBlock)successBlock fail:(failResponseBlock)failBlock {
    NSString * para = [parDict toHttpUrlPara];
    NSString * urlStr = [NSString stringWithFormat:@"%@/user/validateKyc.do?%@",BaseHttpUrl,para];
    
    [BaseService post:urlStr headerDictionay:[[UserInfo sharedUserInfo] getHeaderDic]  timeout:SERVICETIMEOUT success:^(id responseObject) {
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil removingNulls:YES ignoreArrays:NO];
        successBlock(dict);
    } fail:^(NSError *error) {
        failBlock(error);
    }];
}

#pragma mark - 退出
- (void)singout:(successResponseBlock)successBlock fail:(failResponseBlock)failBlock {
    NSString * urlStr = [NSString stringWithFormat:@"%@/user/singout.do",BaseHttpUrl];
    
    [BaseService post:urlStr headerDictionay:[[UserInfo sharedUserInfo] getHeaderDic]  timeout:SERVICETIMEOUT success:^(id responseObject) {
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil removingNulls:YES ignoreArrays:NO];
        successBlock(dict);
    } fail:^(NSError *error) {
        failBlock(error);
    }];
}

#pragma mark - 修改密码
- (void)modifyPwd:(NSDictionary *)parDict success:(successResponseBlock)successBlock fail:(failResponseBlock)failBlock {
    NSString * para = [parDict toHttpUrlPara];
    NSString * urlStr = [NSString stringWithFormat:@"%@/user/modifyPwd.do?%@",BaseHttpUrl,para];
    
    [BaseService post:urlStr headerDictionay:[[UserInfo sharedUserInfo] getHeaderDic]  timeout:SERVICETIMEOUT success:^(id responseObject) {
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil removingNulls:YES ignoreArrays:NO];
        successBlock(dict);
    } fail:^(NSError *error) {
        failBlock(error);
    }];
}

#pragma mark - 添加虚拟币提现地址
- (void)modifyWithdrawBtcAddr:(NSDictionary *)parDict success:(successResponseBlock)successBlock fail:(failResponseBlock)failBlock {
    
    NSString * para = [parDict toHttpUrlPara];
    NSString * urlStr = [NSString stringWithFormat:@"%@/user/modifyWithdrawBtcAddr.do?%@",BaseHttpUrl,para];
    
    [BaseService post:urlStr headerDictionay:[[UserInfo sharedUserInfo] getHeaderDic]  timeout:SERVICETIMEOUT success:^(id responseObject) {
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil removingNulls:YES ignoreArrays:NO];
        successBlock(dict);
    } fail:^(NSError *error) {
        failBlock(error);
    }];
}

#pragma mark - 删除虚拟币提现地址
- (void)detelCoinAddress:(NSDictionary *)parDict success:(successResponseBlock)successBlock fail:(failResponseBlock)failBlock {
    
    NSString * para = [parDict toHttpUrlPara];
    NSString * urlStr = [NSString stringWithFormat:@"%@/user/detelCoinAddress.do?%@",BaseHttpUrl,para];
    
    [BaseService post:urlStr headerDictionay:[[UserInfo sharedUserInfo] getHeaderDic]  timeout:SERVICETIMEOUT success:^(id responseObject) {
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil removingNulls:YES ignoreArrays:NO];
        successBlock(dict);
    } fail:^(NSError *error) {
        failBlock(error);
    }];
}

@end
